<template>
  <div class="head-container">
    <!-- 搜索 -->
    <el-input v-model="query.orderNo" clearable placeholder="订单号" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
    <el-input v-model="query.recvPhone" clearable placeholder="客户手机号" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
    <el-input v-model="query.buylerName" clearable placeholder="购买人" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
    <el-select v-model="query.orderStatus" placeholder="状态" style="width: 200px;" @change="changeType">
      <el-option
        v-for="(item, i) in orderStatusArr"
        :key="i"
        :label="item.name"
        :value="item.status"/>
    </el-select>
    <el-date-picker
      v-model="query.orderBeginDate"
      type="date"
      format="yyyy-MM-dd"
      value-format="yyyy-MM-dd"
      clearable
      placeholder="开始日期"
      style="width: 200px;"
      class="filter-item" 
      @keyup.enter.native="toQuery"/>
    <el-date-picker
      v-model="query.orderEndDate"
      type="date"
      format="yyyy-MM-dd"
      value-format="yyyy-MM-dd"
      clearable
      placeholder="开始日期"
      style="width: 200px;"
      class="filter-item" 
      @keyup.enter.native="toQuery"/>
    <el-button class="filter-item" size="mini" type="primary" icon="el-icon-search" @click="toQuery">搜索</el-button>
    <el-button class="filter-item" size="mini" type="primary" @click="handleExportExcel">导出Excel</el-button>
    <!--<el-button class="filter-item" size="mini" type="primary" @click="check">发货</el-button>
    <el-button class="filter-item" size="mini" type="primary" @click="obsolete">作废</el-button>
    <el-button class="filter-item" size="mini" type="primary" @click="batchDelete">删除</el-button>-->
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import eForm from './form'
export default {
  components: { eForm },
  props: {
    query: {
      type: Object,
      required: true
    },
    permissions: {
      type: Array,
      required: true
    },
    companyLevels: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      downloadLoading: false,
      companyType: "",
      orderStatusArr: [
        {
          status: "1",
          name: "已付款"
        },
        {
          status: "0",
          name: "未付款"
        }
      ]
    }
  },
  methods: {
    checkPermission,
    toQuery() {
      console.log(this.query)
      this.$parent.page = 0
      this.$parent.init()
    },
    changeType(e) {
      this.query.orderStatus = e
      // this.toQuery()
    },
    // 批量作废
    obsolete() {
      const arr = []
      this.$parent.multipleSelection.forEach(v => {
        arr.push({
          orderNo: v.orderNo,
          shopNo: "S0001"
        })
      });
      this.$api.fenxiao.order.cancelBatch({ data: arr }).then(res => {
        this.delLoading = false
        this.$parent.init()
        this.$notify({ title: '作废成功', type: 'success', duration: 2500 })
      }).catch(err => {
        this.delLoading = false
      })
    },
    //批量删除
    batchDelete(){
 const arr = []
      this.$parent.multipleSelection.forEach(v => {
        arr.push({
          orderNo: v.orderNo,
          shopNo: "S0001"
        })
      });
      this.$api.fenxiao.order.batchDelete({ data: arr }).then(res => {
        this.delLoading = false
        this.$parent.init()
        this.$notify({ title: '删除成功', type: 'success', duration: 2500 })
      }).catch(err => {
        this.delLoading = false
      })
    },
    check() {
      const arr = []
      this.$parent.multipleSelection.forEach(v => {
        arr.push({
          orderNo: v.orderNo,
          shopNo: "S0001"
        })
      });
      this.$api.fenxiao.order.check({ data: arr }).then(res => {
        this.delLoading = false
        this.$parent.init()
        this.$notify({ title: '审核成功', type: 'success', duration: 2500 })
      }).catch(err => {
        this.delLoading = false
      })
    },
    handleExportExcel() {
      const url = `https://jinfang.xunyu.shop/admin/order/export?buylerName=${this.query.buylerName || ''}&compNo=${this.query.compNo || ''}&confirmDateBegin=${this.query.confirmDateBegin || ''}&confirmDateEnd=${this.query.confirmDateEnd || ''}&orderDateBegin=${this.query.orderBeginDate || ''}&orderDateEnd=${this.query.orderEndDate || ''}&orderNo=${this.query.orderNo || ''}&orderStatus=${this.query.orderStatus || ''}&pageNum=0&pageSize=0&recvPhone=${this.query.recvPhone || ''}`
      window.open(url)
    }
  }
}
</script>
